package com.dbsop.common.util;

import org.elasticsearch.common.transport.TransportAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class HostsUtils {

    public static TransportAddress getTransportAddress(String host){
        String[] ipPort = host.split(":");
        int port = ipPort.length==1?9200:Integer.valueOf(ipPort[1]);
        try {
            return new TransportAddress(InetAddress.getByName(ipPort[0]), port);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return null;
    }
}
